<%@ Register TagPrefix="freak" Namespace="freak" Assembly = "fricchettone"%>
<%@ Page ContentType="text/xml" ResponseEncoding="ISO-8859-1" ValidateRequest="false" Language="C#" Description="Homepage" debug="false" trace="false" Culture="it-IT" EnableViewState="false"%>
<%@ Import Namespace="dammelau" %>
<%@ Import Namespace="System.Xml" %>
<%
    usrUtil usru = new usrUtil(Page);
    sqlUtil sqlu = new sqlUtil();

    if (usru.isLogged)
    {
        bool found = false;

        if (Request.Url.ToString().Contains("debug"))
            Response.Write("you are logged as:" + usru.nick + "\n");
        if (Request.Url.ToString().Contains("debug"))
            Response.Write("your host is:" + freak.api.GetHost(Page.Request.UserHostName) + "\n");

        foreach (DictionaryEntry Item in Cache)
        {
            if (Convert.ToString(Item.Key).IndexOf("(" + usru.nick + "|") > 0)
            {
                if (Request.Url.ToString().Contains("debug"))
                    Response.Write("you are in the cache with key:" + Convert.ToString(Item.Key) + "\n");
                
                System.TimeSpan duration = new System.TimeSpan(0, 0, 60 * 20);
                XmlDocument xmlDoc = (XmlDocument)Cache.Get(Convert.ToString(Item.Key));
                Cache.Insert(Convert.ToString(Item.Key), xmlDoc, null, DateTime.MaxValue, duration);
                found = true;
                break;
            }
        }
        if (!found)
        {
            if (Request.Url.ToString().Contains("debug"))
                Response.Write("you are not in the cache" + "\n");

            XmlDocument xmlDoc = sqlu.XDocFromSP("exec freak_user_info_get @userid='" + usru.userid.ToString() + "'" + ", @type='SPECIAL'");

            if (Request.Url.ToString().Contains("debug"))
                Response.Write("I will put you in the cache with:" + xmlDoc.OuterXml + "\n");
            if (Request.Url.ToString().Contains("debug"))
                Response.Write("your host will be:" + freak.api.GetHost(Page.Request.UserHostName) + "\n");

            if (xmlDoc.OuterXml != "")
            {
                freak.api apiUtil = new freak.api(Page);
                System.TimeSpan duration = new System.TimeSpan(0, 0, 60 * 20);
                Cache.Insert("online(" + usru.nick + "|" + freak.api.GetHost(Page.Request.UserHostName) + ").doc", xmlDoc, null, DateTime.MaxValue, duration);
            }
        }
    }

    if (Request.Url.ToString().Contains("debug"))
        Response.Write("debug mode" + "\n");
    else
    {
        Response.ContentType = "image/jpeg";
        System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("/poweredbyfricchettone.jpg"));
        img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
    }
%>
